<% if root && page.level == 0 %>
  <% children = [page] %>
<% else %>
  <% children = Concen::Page.where(:parent_id => page.id).asc(:position) %>
<% end %>

<ul class="<%= 'pages' if children.first.level == 0 %>" data-level="<%= children.first.level %>">
  <% for child in children %>
    <li data-id="<%= "page-" + child.id.to_s %>">
      <p class="<%= 'author' if child.authors_as_user.map(&:_id).include? current_concen_user.id %>">
        <span class="handle"></span>
        <%= link_to child.title, edit_concen_page_path(child), :class => "title" %>
        <%= link_to "Add", new_concen_page_path(:parent_id => child.id), :class => "link-button hidden" %>
        <%= link_to "Edit", edit_concen_page_path(child), :class => "link-button hidden" %>
        <%= link_to "Delete", concen_page_path(child), :method => :delete, :confirm => "Are you sure?", :class => "link-button hidden" %>
      </p>
      <% if Concen::Page.where(:parent_id => child.id).count > 0 %>
        <%= render :partial => "nested_list", :locals => {:page => child, :root => false} %>
      <% end %>
    </li>
  <% end %>
</ul>
